package com.godyao.repository;

import com.godyao.model.SecKillGoods;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

@Repository
public interface SecKillGoodsRepository extends JpaRepository<SecKillGoods, Long> {

    @Query(nativeQuery = true, value = "update t_seckill_goods set stock_count  = stock_count - 1 where goods_id = ?1 and now() between start_date and end_date and stock_count > 0")
    @Modifying
    int secKill(Long goodsId);

    @Query(nativeQuery = true, value = "update t_seckill_goods set stock_count  = ?2 where goods_id = ?1")
    @Modifying
    int updateStockCount(Long goodsId, Integer stockCount);
}